package com.yijiupi.plugin.test.listener;

import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent;
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class MyVfsListener implements BulkFileListener {
    @Override
    public void before(@NotNull List<? extends VFileEvent> events) {
        for(VFileEvent vFileEvent:events){
            if(vFileEvent instanceof VFileDeleteEvent){
                System.out.println("删除事件");
                vFileEvent.getFile().getCanonicalPath();
            }
            if(vFileEvent instanceof VFileCreateEvent){
                System.out.println("新建:"+vFileEvent.getPath());
            }
            vFileEvent.isFromRefresh();
            vFileEvent.isValid();
            //是否是保存
            System.out.println(vFileEvent.isFromSave());

            VirtualFile file= vFileEvent.getFile();
            VirtualFileSystem system= vFileEvent.getFileSystem();
        }
    }

    @Override
    public void after(@NotNull List<? extends VFileEvent> events) {
        for(VFileEvent vFileEvent:events){
            if(vFileEvent instanceof VFileDeleteEvent){
                System.out.println("删除事件");
                vFileEvent.getFile().getCanonicalPath();
            }
            if(vFileEvent instanceof VFileCreateEvent){
                System.out.println("新建:"+vFileEvent.getPath());
            }
            vFileEvent.isFromRefresh();
            vFileEvent.isValid();
            //是否是保存
            System.out.println(vFileEvent.isFromSave());

            VirtualFile file= vFileEvent.getFile();
            VirtualFileSystem system= vFileEvent.getFileSystem();
        }
    }
}
